﻿using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbImageBaseTest and is intended
    ///     to contain all TmdbImageBaseTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbImageBaseTest
    {
        /// <summary>
        ///     A test for TmdbImageBase Constructor
        /// </summary>
        [TestMethod]
        public void TmdbImageBaseConstructorTest()
        {
            var target = new TmdbImageBase();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for AspectRatio
        /// </summary>
        [TestMethod]
        public void AspectRatioTest()
        {
            var target = new TmdbImageBase();
            double expected = new Random().Next( 0, Int32.MaxValue );
            target.AspectRatio = expected;
            double actual = target.AspectRatio;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for FilePath
        /// </summary>
        [TestMethod]
        public void FilePathTest()
        {
            var target = new TmdbImageBase();
            string expected = Guid.NewGuid().ToString();
            target.FilePath = expected;
            string actual = target.FilePath;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Height
        /// </summary>
        [TestMethod]
        public void HeightTest()
        {
            var target = new TmdbImageBase();
            int expected = new Random().Next( 0, Int32.MaxValue );
            target.Height = expected;
            int actual = target.Height;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Iso639_1
        /// </summary>
        [TestMethod]
        public void Iso639_1Test()
        {
            var target = new TmdbImageBase();
            string expected = Guid.NewGuid().ToString();
            target.Iso639_1 = expected;
            string actual = target.Iso639_1;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Width
        /// </summary>
        [TestMethod]
        public void WidthTest()
        {
            var target = new TmdbImageBase();
            int expected = new Random().Next( 0, Int32.MaxValue );
            target.Width = expected;
            int actual = target.Width;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem(@"..\..\TestData\image.json.txt")]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbImageBase();
            var jsonContent = File.ReadAllText("image.json.txt");
            var actual = await target.DeserializeJson<TmdbImageBase>(jsonContent);

            Assert.AreEqual(1.78, actual.AspectRatio);
            Assert.AreEqual("/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg", actual.FilePath);
            Assert.AreEqual(720, actual.Height);
            Assert.AreEqual(null, actual.Iso639_1);
            Assert.AreEqual(1280, actual.Width);
        }
    }
}